package cn.db101.api.complex.component

import cn.dev33.satoken.stp.StpUtil
import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.aspectj.lang.annotation.Pointcut
import org.springframework.stereotype.Component
import org.springframework.web.context.request.RequestContextHolder

import org.springframework.web.context.request.ServletRequestAttributes
import javax.servlet.http.HttpServletRequest


/**
 *
 * @author：zooooooooy
 * @date: 2022/7/6 - 10:10
 */
@Component
@Aspect
class LoginAspect {

    @Pointcut("execution(* cn.db101.api.complex.controller..*(..))")
    fun pc() {}

    @Around("pc()")
    fun around(pjp: ProceedingJoinPoint): Any {

        // login url 排除
        val request: HttpServletRequest =
            (RequestContextHolder.currentRequestAttributes() as ServletRequestAttributes).request

        if(!request.servletPath.contains("api/weather/v1")
            && !request.servletPath.contains("api/image/v1")){
            StpUtil.checkLogin()
        }

        return pjp.proceed()
    }

}
